package com.kgc.warehouse.system.controller;

import com.kgc.warehouse.bussness.entity.Goods;
import com.kgc.warehouse.bussness.service.GoodsService;
import com.kgc.warehouse.system.common.ResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Controller
@RequestMapping("echarts")
public class EchartsController {
    @Resource
    private GoodsService goodsService;

    @RequestMapping("getBar")
    @ResponseBody
    public List<Map<String, Object>> getBar() {
        List<Goods> goodsList = goodsService.list();
        List<String> goodsNames = goodsList.stream().map(goods -> {
            return goods.getGoodsname();
        }).collect(Collectors.toList());
        List<String> goodsSize = goodsList.stream().map(goods -> {
            return goods.getSize();
        }).collect(Collectors.toList());
        List<Integer> goodsNumbers = goodsList.stream().map(goods -> {
            return goods.getNumber();
        }).collect(Collectors.toList());
        ArrayList<Map<String,Object>> list = new ArrayList();
        for (int i = 0; i < goodsList.size(); i++) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", goodsNumbers.get(i));
            String name = goodsNames.get(i)+"-"+goodsSize.get(i);
            map.put("name",name);
            System.out.println("map = " + map);
            list.add(map);
        }
        return list;
    }

}
